package geom;
import processing.core.*;
public class Polygon implements PConstants{
	Vector[] points;
	Vector center;
	int drawMode;
	public Polygon(){
		drawMode = POLYGON;
		points = new Vector[0];
		center = new Vector();
	}
	
	public Polygon(int size){
		drawMode = POLYGON;
		points = new Vector[size];
	}
	
	public void paint(PApplet pa){
		pa.beginShape(drawMode);
		for(int i = 0; i < points.length; i++){
			pa.vertex(points[i].x, points[i].y, points[i].z);
		}
		pa.endShape();
	}
	
	public void set(Vector v, int i){
		points[i] = v;
	}
	
	public void add(Vector v){
		Vector[] temp = points;
		points = new Vector[points.length + 1];
		for(int i = 0; i < temp.length; i++)
			points[i] = temp[i];
		points[temp.length] = v;
	}
	
	public void calcCenter(){
		center = new Vector();
		for(int i = 0; i < points.length; i++){
			center.x += points[i].x;
			center.y += points[i].y;
			center.z += points[i].z;
		}
		center.x /= points.length;
		center.y /= points.length;
		center.z /= points.length;
	}
}
